package de.projectgoodmorning.alarm.util;

import java.util.Calendar;

import android.content.Context;
import de.projectgoodmorning.alarm.model.gateway.CombinedAlarm;
import de.projectgoodmorning.alarm.model.gateway.RingAlarm;
import de.projectgoodmorning.alarm.storage.IdCounter;

/**
 * Die AlarmFactory erstellt unterschiedliche Alarm.
 * Diese Klasse folgt dem Factory-Entwurfsmuster.
 */
public class AlarmFactory {

	private static final int OFF = 0;
	
	// NICE COLORS
	private static final int YELLOW = -3840;

	private static final int LIGHT_ORANGE = -14848;
	private static final int ORANGE = -27136;
	
	private static final int LIGHT_RED = -41984;
	private static final int RED = -62720;

	private static final int BLUE = -16773377;
	private static final int GREEN = -10617088;
	
	public static CombinedAlarm createGoodMorningAlarm( Context ctx ) {
		Calendar cal = Calendar.getInstance();
		cal.set( Calendar.HOUR_OF_DAY, 7 );
		cal.set( Calendar.MINUTE, 0 );
		cal.set( Calendar.SECOND, 0 );
		
		
		RingAlarm ring = new RingAlarm( cal );
		CombinedAlarm ca = new CombinedAlarm( ring );
		ca.name = "Good Morning";
		
		// Predefinitions
		ca.addAlarm( -10*60, 	RED );
		ca.addAlarm( -8*60, 	LIGHT_RED );
		
		ca.addAlarm( -6*60, 	ORANGE );
		ca.addAlarm( -4*60, 	LIGHT_ORANGE );
		
		ca.addAlarm( -2*60, 	YELLOW );
		
		// After-definitions
		ca.addAlarm( 5*60, 		BLUE );
		ca.addAlarm( (5*60)+1, 	GREEN );
		
		ca.addAlarm( (5*60)+2,	BLUE );
		ca.addAlarm( (5*60)+3, 	GREEN );
		
		ca.addAlarm( (5*60)+4,	BLUE );
		ca.addAlarm( (5*60)+5, 	GREEN );
		
		ca.addAlarm( (5*60)+6,	BLUE );
		ca.addAlarm( (5*60)+7, 	GREEN );
		
		ca.addAlarm( (5*60)+8, 	OFF );
		
		return ca;
	}
	
	public static CombinedAlarm createTechnoMorningAlarm( Context ctx ) {
		Calendar cal = Calendar.getInstance();
		cal.set( Calendar.HOUR_OF_DAY, 8 );
		cal.set( Calendar.MINUTE, 0 );
		cal.set( Calendar.SECOND, 0 );
		
		RingAlarm ring = new RingAlarm( cal );
		CombinedAlarm ca = new CombinedAlarm( ring );
		ca.name = "Techno-Morning";
		
		// After-definitions
		ca.addAlarm( 1, 	GREEN );
		ca.addAlarm( 2,		BLUE );
		ca.addAlarm( 3, 	RED );
		ca.addAlarm( 4,		YELLOW );
		ca.addAlarm( 5,		ORANGE );

		ca.addAlarm( 6, 	GREEN );
		ca.addAlarm( 7,		BLUE );
		ca.addAlarm( 8, 	RED );
		ca.addAlarm( 9,		YELLOW );
		ca.addAlarm( 10,	ORANGE );

		ca.addAlarm( 11, 	GREEN );
		ca.addAlarm( 12,	BLUE );
		ca.addAlarm( 13, 	RED );
		ca.addAlarm( 14,	YELLOW );
		ca.addAlarm( 15,	ORANGE );
		
		ca.addAlarm( 16, 	GREEN );
		ca.addAlarm( 17,	BLUE );
		ca.addAlarm( 18, 	RED );
		ca.addAlarm( 19,	YELLOW );
		ca.addAlarm( 20,	ORANGE );
		
		ca.addAlarm( 21, OFF );
		return ca;
	}
	
	public static RingAlarm createRingAlarm( int seconds, Context ctx ) {
		Calendar cal = Calendar.getInstance();
		cal.add( Calendar.SECOND, seconds );
		
		RingAlarm r = new RingAlarm( cal );
		r.id = new IdCounter( ctx ).nextID();
		return r;
	}
}